<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *商品评价管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
//商品评价
$return['stars']=array(
		'1'=>'一星',
		'2'=>'二星',
		'3'=>'三星',
		'4'=>'四星',
		'5'=>'五星',
);
$tabs=array(
	array('op'=>'list','title'=>'评价列表'),
);
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$orderid=intval($_RQ['orderid']);
	if($orderid){
		$params['orderid']=$orderid;
		$return['params']['orderid']=$orderid;
	}
	$mid=intval($_RQ['mid']);
	if($mid){
		$params['mid']=$mid;
		$return['params']['mid']=$mid;
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array();
	$list=pdo_getslice('jy_peiorder_pingjia',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
				$item['member']=model('core/core')->member_show($item['mid']);
				if($item['peisong_id']){
					$item['peimember']=pdo_get('jy_peiorder_member',array('mid'=>$item['peisong_id'],'uniacid'=>$_SESSION['uniacid']),array('title','mobile','level_id'));
					$item['peimember']['nickname']=$item['peimember']['title'];
					$item['peimember']['level']=pdo_getcolumn('jy_peiorder_level',array('id'=>$item['peimember']['level_id'],'uniacid'=>$_SESSION['uniacid']),'title');
					$item['peimember']['level']=$item['peimember']['level']?:'普通等级';
				}
				$item['log']=pdo_get('jy_peiorder_sendlog',array('id'=>$item['log_id'],'uniacid'=>$_SESSION['uniacid']));
		}
	}
	
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'[温馨提示]：</br>1、可以设置好评奖励，差评处罚！','edit'=>false,'list'=>array(
			array('name'=>'orderid','title'=>'订单ID','type'=>'string'),
			array('name'=>'log.day','title'=>'日期','type'=>'string'),
			array('name'=>'member','title'=>'会员','type'=>'member'),
			array('name'=>'peimember','title'=>'配送员','type'=>'member'),
			array('name'=>'content','title'=>'评价内容','type'=>'string'),
			array('name'=>'star','title'=>'评价星级','type'=>'radio','options'=>'stars'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),			
		)),
		'search'=>array(
			array('type'=>'choose','width'=>15,'action'=>'jy_merch/member.get_member/','name'=>'mid','title'=>'选择会员'),
			array('name'=>'orderid','width'=>10,'title'=>'订单ID','type'=>'string'),
		),
		
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='set'){
	$post=get_postdata();
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择评价！','error');
	}
	$show=intval($post['show']);
	$this->pdo_update('pingjia',array('show'=>$show),array('id'=>$id));
	$message=$show?'已显示':'已隐藏';
	exi($message,'error');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_peiorder_pingjia',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}